package net.wenku8.reader.view.common

import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

open class BaseViewModel : ViewModel() {

    val hostState = SnackbarHostState()
    var dataLoading = mutableStateOf(false)

    fun showSnackbar(message: String?){
        if (message == null){
            return
        }
        viewModelScope.launch(Dispatchers.Main) {
            hostState.currentSnackbarData?.dismiss()
            hostState.showSnackbar(message)
        }
    }

}